package com.mincko.minckotest.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.googlecode.objectify.Objectify;
import com.mincko.minckotest.PMF;
import com.mincko.minckotest.shared.Image;
import com.google.gson.Gson;

public class getImages extends HttpServlet {
	private Objectify ofy;
    public void doPost(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
    	
    	String websiteComponentIdentifier = req.getParameter("id");
    	//listing the table
    	Objectify ofy = PMF.getObjectify();
    	com.googlecode.objectify.Query<Image> q = ofy.query(Image.class).filter("webComponentIdentifier",websiteComponentIdentifier);
    	q.order("order");
    	// return to client
		res.setContentType("application/json");
		res.setCharacterEncoding("utf-8");
		res.getWriter().write((new Gson().toJson(q.list())));
				
    }
    //to support get via $.getJson
    public void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
    	doPost(req, res);
    }

}

